<?php

class Diklat extends Controller {

	function Diklat() {
		parent::Controller();
        $this->load->model('Diklat_model', 'p');
	}
	
	function index() {
    	redirect("/welcome", "refresh");
	}
	
	function struktural() {
		if (!$this->session->userdata('username')) {
			$data['isLogin'] = FALSE;
        	redirect("/login", "location");
		} else {
			$data['isLogin'] = TRUE;
			$data['username'] = $this->session->userdata('username');
			$data['role'] = $this->session->userdata('role');
		}

    	$list_nip = $this->_getNIP();
    	if ($list_nip<>'') {
    		$auto_nip = '$("#nip").autocompleteArray(['.$list_nip.'], {delay:10,minChars:1,matchSubset:1,cacheLength:10,maxItemsToShow:10});'; 
    	}
		$data['additional_js'] = '
		<script type="text/javascript">
        	$(function() {
		        $("#nip").focus();'.$auto_nip.
			'});		        
		function deleteRow(id) {
			var txt = \'Anda yakin mau menghapus data diklat ini?<input type="hidden" id="row-id" name="row-id" value="\'+ id +\'" />\';
				url = "'.base_url().'index.php/diklat/hapus/"+id+"/struktural";
			 $.ajax({
			   type: "POST",
			   url: "'.base_url().'index.php/diklat/diklat_bisa_dihapus/"+id,
			   success: function(msg) {
				 if (msg==\'bisa\') {
					$.prompt(txt,{
						buttons:{Hapus:true, Batal:false},
						callback: function(v){
							if(v) {
								$("tr#row-"+id).fadeOut("slow", function() {
									$("tr#row-"+id).remove();
								});
								top.location.href=url;
							}
						}
					});
				 } else {
					alert(\'Maaf, data Diklat tidak dapat dihapus dikarenakan terkait dengan data lain.\');
				 }
		       }
		    });
		}
		</script>
		';
		
		$data['judul'] = 'RIWAYAT DIKLAT STRUKTURAL';
        if( $data['role'] == 0)
            $nip = $this->session->userdata('nip');
        else if ($this->uri->segment(3) == 'nip')
            $nip = $this->uri->segment(4);
        else
		    $nip = $this->input->post('nip')?$this->input->post('nip'):"";
        $this->session->set_userdata(array('nip' => $nip));    
		$data['list_data'] = $this->p->list_diklat_struktural($nip);
        $data['panel'] = $this->_setPanelStruktural($nip);
        $data['tampilkan_menu'] = true;
        $data['jenis_diklat'] = 'struktural';
         	
        if($this->input->post('page'))echo $data['list_data'];
        else $this->load->view('view_diklat',$data);
    }

	function fungsional() {
        if (!$this->session->userdata('username')) {
            $data['isLogin'] = FALSE;
            redirect("/login", "location");
        } else {
            $data['isLogin'] = TRUE;
            $data['username'] = $this->session->userdata('username');
            $data['role'] = $this->session->userdata('role');
        }

        $list_nip = $this->_getNIP();
        if ($list_nip<>'') {
            $auto_nip = '$("#nip").autocompleteArray(['.$list_nip.'], {delay:10,minChars:1,matchSubset:1,cacheLength:10,maxItemsToShow:10});'; 
        }
        $data['additional_js'] = '
        <script type="text/javascript">
            $(function() {
                $("#nip").focus();'.$auto_nip.
            '});                
        function deleteRow(id) {
            var txt = \'Anda yakin mau menghapus data diklat ini?<input type="hidden" id="row-id" name="row-id" value="\'+ id +\'" />\';
                url = "'.base_url().'index.php/diklat/hapus/"+id+"/fungsional";
             $.ajax({
               type: "POST",
               url: "'.base_url().'index.php/diklat/diklat_bisa_dihapus/"+id,
               success: function(msg) {
                 if (msg==\'bisa\') {
                    $.prompt(txt,{
                        buttons:{Hapus:true, Batal:false},
                        callback: function(v){
                            if(v) {
                                $("tr#row-"+id).fadeOut("slow", function() {
                                    $("tr#row-"+id).remove();
                                });
                                top.location.href=url;
                            }
                        }
                    });
                 } else {
                    alert(\'Maaf, data Diklat tidak dapat dihapus dikarenakan terkait dengan data lain.\');
                 }
               }
            });
        }
        </script>
        ';
        
        $data['judul'] = 'RIWAYAT DIKLAT FUNGSIONAL';
        if( $data['role'] == 0)
            $nip = $this->session->userdata('nip');
        else if ($this->uri->segment(3) == 'nip')
            $nip = $this->uri->segment(4);
        else
            $nip = $this->input->post('nip')?$this->input->post('nip'):"";
        $this->session->set_userdata(array('nip' => $nip));    
        $data['list_data'] = $this->p->list_diklat_fungsional($nip);
        $data['panel'] = $this->_setPanelFungsional($nip);
        $data['tampilkan_menu'] = true;
        $data['jenis_diklat'] = 'fungsional';
                
        if($this->input->post('page'))echo $data['list_data'];
        else $this->load->view('view_diklat',$data);
    }
    function teknis() {
		if (!$this->session->userdata('username')) {
			$data['isLogin'] = FALSE;
        	redirect("/login", "location");
		} else {
			$data['isLogin'] = TRUE;
			$data['username'] = $this->session->userdata('username');
			$data['role'] = $this->session->userdata('role');
		}

    	$list_nip = $this->_getNIP();
    	if ($list_nip<>'') {
    		$auto_nip = '$("#nip").autocompleteArray(['.$list_nip.'], {delay:10,minChars:1,matchSubset:1,cacheLength:10,maxItemsToShow:10});'; 
    	}
		$data['additional_js'] = '
		<script type="text/javascript">
        	$(function() {
		        $("#nip").focus();'.$auto_nip.
			'});		        
		function deleteRow(id) {
			var txt = \'Anda yakin mau menghapus data diklat ini?<input type="hidden" id="row-id" name="row-id" value="\'+ id +\'" />\';
				url = "'.base_url().'index.php/diklat/hapus/"+id+"/teknis";
			 $.ajax({
			   type: "POST",
			   url: "'.base_url().'index.php/diklat/diklat_bisa_dihapus/"+id,
			   success: function(msg) {
				 if (msg==\'bisa\') {
					$.prompt(txt,{
						buttons:{Hapus:true, Batal:false},
						callback: function(v){
							if(v) {
								$("tr#row-"+id).fadeOut("slow", function() {
									$("tr#row-"+id).remove();
								});
                                $.post(url); 
								//top.location.href=url;
							}
						}
					});
				 } else {
					alert(\'Maaf, data Diklat tidak dapat dihapus dikarenakan terkait dengan data lain.\');
				 }
		       }
		    });
		}
		</script>
		';
		
		$data['judul'] = 'RIWAYAT DIKLAT TEKNIS';
        if( $data['role'] == 0)
            $nip = $this->session->userdata('nip');
        else if ($this->uri->segment(3) == 'nip')
            $nip = $this->uri->segment(4);
        else
		    $nip = $this->input->post('nip')?$this->input->post('nip'):"";
        $this->session->set_userdata(array('nip' => $nip));    
		$data['list_data'] = $this->p->list_diklat_teknis($nip);
        $data['panel'] = $this->_setPanelTeknis($nip);
        $data['tampilkan_menu'] = true;
        $data['jenis_diklat'] = 'teknis';
         
        if($this->input->post('page'))echo $data['list_data'];
        else $this->load->view('view_diklat',$data);
    }

    function _getNIP() {
    	$this->db->order_by('nip', 'asc');
    	$q = $this->db->get('pegawai');
    	$list = '';
    	if ($q->num_rows() > 0) {
	    	foreach ($q->result() as $row) {
	    		$list .= '"'.$row->nip.'",';
	    	}
	    	$list = substr($list, 0, -1);
    	}
    	return $list;
    }
    
    function _setPanelStruktural($nip) {
    	$info_pegawai = '';
    	if ($nip!="") {
            $this->db->select('gelar_depan, nama, gelar_belakang');
            $this->db->where(array('nip' => $nip));
			$this->db->or_where(array('nip_baru' => $nip));
			$query = $this->db->get('pegawai');
			if ($query->num_rows() > 0) {
				$r = $query->row();
				$info_pegawai = sprintf("%s %s %s", $r->gelar_depan, $r->nama, $r->gelar_belakang);
			} else {
				$info_pegawai = '-';
			}
		}
    	$ret =  form_open('diklat/struktural').
				"<fieldset >
				 <table class=\"formTabel\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\">
				  <tr>
				    <td class=\"kolom\" valign=\"top\">NIP : <input type=\"text\" name=\"nip\" id=\"nip\" value=\"".$nip."\" /></td>
				    <td valign=\"top\"><input class=\"tombol\" type=\"submit\" name=\"button\" id=\"button\" value=\"Tampilkan\" /></td>
				    <td valign=\"top\"><div id=\"info_pegawai\">".$info_pegawai."</div></td>
				 </tr>
				 </table>
				 </fieldset>".
				 form_close();
		return $ret;    	
    }
    
    function _setPanelFungsional($nip) {
        $info_pegawai = '';
        if ($nip!="") {
            $this->db->select('gelar_depan, nama, gelar_belakang');
            $this->db->where(array('nip' => $nip));
            $this->db->or_where(array('nip_baru' => $nip));
            $query = $this->db->get('pegawai');
            if ($query->num_rows() > 0) {
                $r = $query->row();
                $info_pegawai = sprintf("%s %s %s", $r->gelar_depan, $r->nama, $r->gelar_belakang);
            } else {
                $info_pegawai = '-';
            }
        }
        $ret =  form_open('diklat/Fungsional').
                "<fieldset >
                 <table class=\"formTabel\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\">
                  <tr>
                    <td class=\"kolom\" valign=\"top\">NIP : <input type=\"text\" name=\"nip\" id=\"nip\" value=\"".$nip."\" /></td>
                    <td valign=\"top\"><input class=\"tombol\" type=\"submit\" name=\"button\" id=\"button\" value=\"Tampilkan\" /></td>
                    <td valign=\"top\"><div id=\"info_pegawai\">".$info_pegawai."</div></td>
                 </tr>
                 </table>
                 </fieldset>".
                 form_close();
        return $ret;        
    }
    
    function _setPanelTeknis($nip) {
    	$info_pegawai = '';
    	if ($nip!="") {
            $this->db->select('gelar_depan, nama, gelar_belakang');
            $this->db->where(array('nip' => $nip));
			$this->db->or_where(array('nip_baru' => $nip));
			$query = $this->db->get('pegawai');
			if ($query->num_rows() > 0) {
				$r = $query->row();
				$info_pegawai = sprintf("%s %s %s", $r->gelar_depan, $r->nama, $r->gelar_belakang);
			} else {
				$info_pegawai = '-';
			}
		}
    	$ret =  form_open('diklat/teknis').
				"<fieldset >
				 <table class=\"formTabel\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\">
				  <tr>
				    <td class=\"kolom\" valign=\"top\">NIP : <input type=\"text\" name=\"nip\" id=\"nip\" value=\"".$nip."\" /></td>
				    <td valign=\"top\"><input class=\"tombol\" type=\"submit\" name=\"button\" id=\"button\" value=\"Tampilkan\" /></td>
				    <td valign=\"top\"><div id=\"info_pegawai\">".$info_pegawai."</div></td>
				 </tr>
				 </table>
				 </fieldset>".
				 form_close();
		return $ret;    	
    }
    
    function _setJsFormStruktural($additional_string) {
    	$ret = '
		<script type="text/javascript">
        	$(function() {
		        $("#nip").focus();'.
		        $additional_string.
                '$("#btn_kembali").click( function() {
                    window.location = \''.base_url().'index.php/diklat/struktural\';
                });
                // validate contact form on keyup and submit
                $("form").validate({
                    '.$this->_setRulesStruktural().'
                });
                $("form").submit(function() {
                	var nip = $("#nip").val();
			 		$.ajax({
					   type: "POST",
					   url: "'.base_url().'index.php/jabatan/cek_nip/"+nip,
					   success: function(msg) {
						 if (msg!=\'valid\') {
						 	$.prompt(\'Maaf, NIP "\'+nip+\'" tidak terdaftar. Silahkan periksa lagi.\'+msg);
							$("#nip").focus();
							return false;
						 }
				       }
		    		});
    			});
        	});
        </script>
    	';
    	return $ret;
    }
    
    function _setJsFormFungsional($additional_string) {
        $ret = '
        <script type="text/javascript">
            $(function() {
                $("#nip").focus();'.
                $additional_string.
                '$("#btn_kembali").click( function() {
                    window.location = \''.base_url().'index.php/diklat/fungsional\';
                });
                // validate contact form on keyup and submit
                $("form").validate({
                    '.$this->_setRulesFungsional().'
                });
                $("form").submit(function() {
                    var nip = $("#nip").val();
                     $.ajax({
                       type: "POST",
                       url: "'.base_url().'index.php/jabatan/cek_nip/"+nip,
                       success: function(msg) {
                         if (msg!=\'valid\') {
                             $.prompt(\'Maaf, NIP "\'+nip+\'" tidak terdaftar. Silahkan periksa lagi.\'+msg);
                            $("#nip").focus();
                            return false;
                         }
                       }
                    });
                });
            });
        </script>
        ';
        return $ret;
    }
    
    function _setJsFormTeknis($additional_string) {
    	$ret = '
		<script type="text/javascript">
        	$(function() {
		        $("#nip").focus();'.
		        $additional_string.
                '$("#btn_kembali").click( function() {
                    window.location = \''.base_url().'index.php/diklat/teknis\';
                });
                // validate contact form on keyup and submit
                $("form").validate({
                    '.$this->_setRulesTeknis().'
                });
                $("form").submit(function() {
                	var nip = $("#nip").val();
			 		$.ajax({
					   type: "POST",
					   url: "'.base_url().'index.php/jabatan/cek_nip/"+nip,
					   success: function(msg) {
						 if (msg!=\'valid\') {
						 	$.prompt(\'Maaf, NIP "\'+nip+\'" tidak terdaftar. Silahkan periksa lagi.\'+msg);
							$("#nip").focus();
							return false;
						 }
				       }
		    		});
    			});
        	});
        </script>
    	';
    	return $ret;
    }
    
    function _getPegawai() {
    	$this->db->order_by('nama', 'asc');
    	$q = $this->db->get('pegawai');
    	$list_pegawai = '';
    	foreach ($q->result() as $row) {
    		$list_pegawai .= '"'.$row->nama.'",';
    	}
    	$list_pegawai = substr($list_pegawai, 0, -1);
    	return $list_pegawai;
    }
    
    function _setRulesStruktural() {
    	return '
                    //set the rules for the field names
                    rules: {
                        nip: { required: true },
                        id_jenis_diklat_struktural: { required: true },
                        y_tgl_mulai: { required: true },
                        y_tgl_selesai: { required: true },
                        tempat: { required: true },
                        y_tgl_sttp: { required: true }
    				},
                    //set messages to appear inline
                    messages: {
                        nip: "NIP wajib diisi",
                        id_jenis_diklat_struktural: "Kategori Diklat Struktural wajib diisi",
                        y_tgl_mulai: "Tahun Mulai wajib diisi",
                        y_tgl_selesai: "Tahun Selesai wajib diisi",
                        tempat: "Penyelenggara/Tempat wajib diisi",
                        y_tgl_sttp: "Tahun STTP wajib diisi"
    				}
    	';
    }
    
    function _setRulesFungsional() {
        return '
                    //set the rules for the field names
                    rules: {
                        nip: { required: true },
                        
                        nama: { required: true },
                        angkatan: { required: true },
                        tahun: { required: true },
                        tempat: { required: true },
                        y_tgl_sttp: { required: true }
                    },
                    //set messages to appear inline
                    messages: {
                        nip: "NIP wajib diisi",
                        
                        nama: "Nama wajib diisi",
                        angkatan: "Angkatan wajib diisi",
                        tahun: "Tahun wajib diisi",
                        tempat: "Penyelenggara/Tempat wajib diisi",
                        y_tgl_sttp: "Tahun STTP wajib diisi"
                    }
        ';
    }
    function _setRulesTeknis() {
    	return '
                    //set the rules for the field names
                    rules: {
                        nip: { required: true },
                       
                        nama: { required: true },
                        angkatan: { required: true },
                        tahun: { required: true },
                        tempat: { required: true },
                        y_tgl_sttp: { required: true }
    				},
                    //set messages to appear inline
                    messages: {
                        nip: "NIP wajib diisi",
                       
                        nama: "Nama wajib diisi",
                        angkatan: "Angkatan wajib diisi",
                        tahun: "Tahun wajib diisi",
                        tempat: "Penyelenggara/Tempat wajib diisi",
                        y_tgl_sttp: "Tahun STTP wajib diisi"
    				}
    	';
    }
    
    function form_isian_struktural() {
		if (!$this->session->userdata('username')) {
			$data['isLogin'] = FALSE;
        	redirect("/login", "location");
		} else {
			$data['isLogin'] = TRUE;
			$data['username'] = $this->session->userdata('username');
			$data['role'] = $this->session->userdata('role');
		}
		
    	$list_nip = $this->_getNIP();
    	if ($list_nip<>'') {
    		$auto_nip = '$("#nip").autocompleteArray(['.$list_nip.'], {delay:10,minChars:1,matchSubset:1,autoFill:true,maxItemsToShow:10});'; 
    	} else {
    		$auto_nip = ''; 
    	}
        $data['additional_js'] = $this->_setJsFormStruktural($auto_nip);
		           
        $data['judul'] = 'INPUT DATA DIKLAT STRUKTURAL';
        $form_action = base_url().'index.php/diklat/simpan_struktural';
        $form_id = 'form_diklat';
        $data['list_data'] = $this->p->entry_diklat_struktural($form_id,$form_action);
        $this->load->view('view_diklat', $data);
    }
    
    function form_isian_fungsional() {
        if (!$this->session->userdata('username')) {
            $data['isLogin'] = FALSE;
            redirect("/login", "location");
        } else {
            $data['isLogin'] = TRUE;
            $data['username'] = $this->session->userdata('username');
            $data['role'] = $this->session->userdata('role');
        }
        
        $list_nip = $this->_getNIP();
        if ($list_nip<>'') {
            $auto_nip = '$("#nip").autocompleteArray(['.$list_nip.'], {delay:10,minChars:1,matchSubset:1,autoFill:true,maxItemsToShow:10});'; 
        } else {
            $auto_nip = ''; 
        }
        $data['additional_js'] = $this->_setJsFormFungsional($auto_nip);
                   
        $data['judul'] = 'INPUT DATA DIKLAT FUNGSIONAL';
        $form_action = base_url().'index.php/diklat/simpan_fungsional';
        $form_id = 'form_diklat';
        $data['list_data'] = $this->p->entry_diklat_fungsional($form_id,$form_action);
        $this->load->view('view_diklat', $data);
    }
    function form_isian_teknis() {
		if (!$this->session->userdata('username')) {
			$data['isLogin'] = FALSE;
        	redirect("/login", "location");
		} else {
			$data['isLogin'] = TRUE;
			$data['username'] = $this->session->userdata('username');
			$data['role'] = $this->session->userdata('role');
		}
		
    	$list_nip = $this->_getNIP();
    	if ($list_nip<>'') {
    		$auto_nip = '$("#nip").autocompleteArray(['.$list_nip.'], {delay:10,minChars:1,matchSubset:1,autoFill:true,maxItemsToShow:10});'; 
    	} else {
    		$auto_nip = ''; 
    	}
        $data['additional_js'] = $this->_setJsFormTeknis($auto_nip);
		           
        $data['judul'] = 'INPUT DATA DIKLAT TEKNIS';
        $form_action = base_url().'index.php/diklat/simpan_teknis';
        $form_id = 'form_diklat';
        $data['list_data'] = $this->p->entry_diklat_teknis($form_id,$form_action);
        $this->load->view('view_diklat', $data);
    }
    
    function simpan_struktural($is_update=FALSE, $id='') {
        $this->load->model('Datum_model', 'd');
    	if (!$this->input->post('nip')) {
            redirect('diklat', 'refresh');
			
        } else {
			
            $id_pegawai = $this->d->getData('idspg_pegawai', 'pegawai', array('nip_baru' => $this->input->post('nip')));
        	$arr['id_pegawai'] = $id_pegawai!=false?$id_pegawai:$this->d->getData('idspg_pegawai', 'pegawai', array('nip' => $this->input->post('nip')));
        }
		
        if ($arr['id_pegawai'] == false) {
            echo "<script>alert('NIP : ".$this->input->post('nip')." tidak terdaftar');                          
                          window.history.back();  
            </script>";
            return false;
        }
        $arr['id_jenis_diklat'] = TIPE_DIKLAT_STRUKTURAL;
        /*if ($this->input->post('id_jenis_diklat_struktural')) {          
        	$arr['id_jenis_diklat_struktural'] = $this->input->post('id_jenis_diklat_struktural');
        } else {
        	$data['judul'] = 'ERROR';
        	$data['isi']   = 'Internal error [id_jenis_diklat_struktural].';
        	$data['link_kembali'] = base_url().'index.php/diklat/struktural';
        	$this->load->view('view_blank', $data);
        }
		*/
        if ($this->input->post('d_tgl_mulai')) {
        	$a = array($this->input->post('y_tgl_mulai'), $this->input->post('m_tgl_mulai'), $this->input->post('d_tgl_mulai'));
            $arr['tgl_mulai'] = implode(TGL_SEPARATOR, $a);
        } else {
            $arr['tgl_mulai'] = date("Y-m-d");
        }
        if ($this->input->post('d_tgl_selesai')) {
        	$a = array($this->input->post('y_tgl_selesai'), $this->input->post('m_tgl_selesai'), $this->input->post('d_tgl_selesai'));
            $arr['tgl_selesai'] = implode(TGL_SEPARATOR, $a);
        } else {
            $arr['tgl_selesai'] = date("Y-m-d");
        }
        if ($this->input->post('d_tgl_sttp')) {
        	$a = array($this->input->post('y_tgl_sttp'), $this->input->post('m_tgl_sttp'), $this->input->post('d_tgl_sttp'));
            $arr['tgl_sttp'] = implode(TGL_SEPARATOR, $a);
        } else {
            $arr['tgl_sttp'] = date("Y-m-d");
        }
        $arr['tempat'] = $this->input->post('tempat')?$this->input->post('tempat'):"";
        $arr['total_jam'] = $this->input->post('total_jam')?$this->input->post('total_jam'):"0";
        $arr['no_sttp'] = $this->input->post('no_sttp')?$this->input->post('no_sttp'):"";
		$arr['nama'] = $this->input->post('nama')?$this->input->post('nama'):"";
        
        
        if ($is_update) {
        	$this->p->simpan($arr, $is_update, $id);
        	redirect('diklat/struktural/nip/'.$this->input->post('nip'), 'refresh');
        } else {
        	$this->p->simpan($arr);
        	redirect('diklat/form_isian_struktural', 'refresh');
			redirect('diklat/struktural/nip/'.$this->input->post('nip'), 'refresh');
        }
    }
    
    function simpan_fungsional($is_update=FALSE, $id='') {
        $this->load->model('Datum_model', 'd');
        if (!$this->input->post('nip')) {
            redirect('diklat', 'refresh');
        } else {
            $id_pegawai = $this->d->getData('idspg_pegawai', 'pegawai', array('nip_baru' => $this->input->post('nip')));
            $arr['id_pegawai'] = $id_pegawai!=false?$id_pegawai:$this->d->getData('idspg_pegawai', 'pegawai', array('nip' => $this->input->post('nip')));
        }
        if ($arr['id_pegawai'] == false) {
            echo "<script>alert('NIP : ".$this->input->post('nip')." tidak terdaftar');                          
                          window.history.back();  
            </script>";
            return false;
        }
        if ($this->input->post('d_tgl_sttp')) {
            $a = array($this->input->post('y_tgl_sttp'), $this->input->post('m_tgl_sttp'), $this->input->post('d_tgl_sttp'));
            $arr['tgl_sttp'] = implode(TGL_SEPARATOR, $a);
        } else {
            $arr['tgl_sttp'] = date("Y-m-d");
        }
        $arr['nama'] = $this->input->post('nama')?$this->input->post('nama'):"";
        $arr['id_jenis_diklat'] = $this->input->post('id_jenis_diklat')?$this->input->post('id_jenis_diklat'):"";
        $arr['tempat'] = $this->input->post('tempat')?$this->input->post('tempat'):"";
        $arr['lama_pendidikan'] = $this->input->post('lama_pendidikan')?$this->input->post('lama_pendidikan'):"0";
        $arr['angkatan'] = $this->input->post('angkatan')?$this->input->post('angkatan'):"";
        $arr['tahun'] = $this->input->post('tahun')?$this->input->post('tahun'):"";
        $arr['no_sttp'] = $this->input->post('no_sttp')?$this->input->post('no_sttp'):"";
        $arr['id_jenis_diklat'] = TIPE_DIKLAT_FUNGSIONAL;
        
        #if ($is_update) {
            $this->p->simpan($arr, $is_update, $id);
            redirect('diklat/fungsional/nip/'.$this->input->post('nip'), 'refresh');
        /*} else {
            $this->p->simpan($arr);
            redirect('diklat/form_isian_fungsional', 'refresh');
        }*/
    }
    function simpan_teknis($is_update=FALSE, $id='') {
        $this->load->model('Datum_model', 'd');
    	if (!$this->input->post('nip')) {
            redirect('diklat', 'refresh');
        } else {
            $id_pegawai = $this->d->getData('idspg_pegawai', 'pegawai', array('nip_baru' => $this->input->post('nip')));
            $arr['id_pegawai'] = $id_pegawai!=false?$id_pegawai:$this->d->getData('idspg_pegawai', 'pegawai', array('nip' => $this->input->post('nip')));
        }
        if ($arr['id_pegawai'] == false) {
            echo "<script>alert('NIP : ".$this->input->post('nip')." tidak terdaftar');                          
                          window.history.back();  
            </script>";
            return false;
        }
        if ($this->input->post('d_tgl_sttp')) {
        	$a = array($this->input->post('y_tgl_sttp'), $this->input->post('m_tgl_sttp'), $this->input->post('d_tgl_sttp'));
            $arr['tgl_sttp'] = implode(TGL_SEPARATOR, $a);
        } else {
            $arr['tgl_sttp'] = date("Y-m-d");
        }
        $arr['nama'] = $this->input->post('nama')?$this->input->post('nama'):"";
        $arr['id_jenis_diklat'] = $this->input->post('id_jenis_diklat')?$this->input->post('id_jenis_diklat'):"";
        $arr['tempat'] = $this->input->post('tempat')?$this->input->post('tempat'):"";
        $arr['lama_pendidikan'] = $this->input->post('lama_pendidikan')?$this->input->post('lama_pendidikan'):"0";
        $arr['angkatan'] = $this->input->post('angkatan')?$this->input->post('angkatan'):"";
        $arr['tahun'] = $this->input->post('tahun')?$this->input->post('tahun'):"";
        $arr['no_sttp'] = $this->input->post('no_sttp')?$this->input->post('no_sttp'):"";
        $arr['id_jenis_diklat'] = TIPE_DIKLAT_TEKNIS;
        
        #if ($is_update) {
        	$this->p->simpan($arr, $is_update, $id);
        	redirect('diklat/teknis/nip/'.$this->input->post('nip'), 'refresh');
        /*} else {
        	$this->p->simpan($arr);
        	redirect('diklat/form_isian_teknis', 'refresh');
        }*/
    }
    
    function form_edit_struktural($id) {
		if (!$this->session->userdata('username')) {
			$data['isLogin'] = FALSE;
        	redirect("/login", "location");
		} else {
			$data['isLogin'] = TRUE;
			$data['username'] = $this->session->userdata('username');
			$data['role'] = $this->session->userdata('role');
		}
		
    	$form_action = base_url().'index.php/diklat/simpan_struktural/true/'.$id;
        $form_id = 'form_diklat';
    	$list_nip = $this->_getNIP();
    	if ($list_nip<>'') {
    		$auto_nip = '$("#nip").autocompleteArray(['.$list_nip.'], {delay:10,minChars:1,matchSubset:1,autoFill:true,maxItemsToShow:10});'; 
    	} else {
    		$auto_nip = ''; 
    	}
        $data['additional_js'] = $this->_setJsFormStruktural($auto_nip);
                
        $this->load->model('Datum_model', 'd');
        $this->db->where(array('idspg_diklat' => $id));
        $q = $this->db->get('diklat');
        if ($q->num_rows() > 0) {
            $row = $q->row();
            $nip2 = $this->d->getData('nip_baru', 'pegawai', array('idspg_pegawai' => $row->id_pegawai));
            $arr['nip']          				= $nip2!=''?$nip2:$this->d->getData('nip', 'pegawai', array('idspg_pegawai' => $row->id_pegawai));
            $arr['id_jenis_diklat_struktural']  = $row->id_jenis_diklat_struktural;
            $arr['tgl_mulai']         			= $row->tgl_mulai;
            $arr['tgl_selesai']           		= $row->tgl_selesai;
            $arr['total_jam']          			= $row->total_jam;
            $arr['tempat']         				= $row->tempat;
            $arr['no_sttp']         			= $row->no_sttp;
            $arr['tgl_sttp']         			= $row->tgl_sttp;
            
            $form_action = base_url().'index.php/diklat/simpan_struktural/true/'.$id;
            $form_id = 'form_diklat';
            
            $data['judul'] = 'UBAH DATA DIKLAT STRUKTURAL';
            $data['list_data'] = $this->p->entry_diklat_struktural($form_id,$form_action,$arr);
            $this->load->view('view_diklat', $data);
        } else {
        	$data['judul'] = 'ERROR';
        	$data['isi']   = 'Internal ID error.';
        	$data['link_kembali'] = base_url().'index.php/diklat/struktural';
        	$this->load->view('view_blank', $data);
        }
    }

    function form_edit_fungsional($id) {
        if (!$this->session->userdata('username')) {
            $data['isLogin'] = FALSE;
            redirect("/login", "location");
        } else {
            $data['isLogin'] = TRUE;
            $data['username'] = $this->session->userdata('username');
            $data['role'] = $this->session->userdata('role');
        }
        
        $form_action = base_url().'index.php/diklat/simpan_fungsional/true/'.$id;
        $form_id = 'form_diklat';
        $list_nip = $this->_getNIP();
        if ($list_nip<>'') {
            $auto_nip = '$("#nip").autocompleteArray(['.$list_nip.'], {delay:10,minChars:1,matchSubset:1,autoFill:true,maxItemsToShow:10});'; 
        } else {
            $auto_nip = ''; 
        }
        $data['additional_js'] = $this->_setJsFormFungsional($auto_nip);

        $this->load->model('Datum_model', 'd');
        $this->db->where(array('idspg_diklat' => $id));
        $q = $this->db->get('diklat');
        if ($q->num_rows() > 0) {
            $row = $q->row();
            $nip2 = $this->d->getData('nip_baru', 'pegawai', array('idspg_pegawai' => $row->id_pegawai));
            $arr['nip']                          = $nip2!=''?$nip2:$this->d->getData('nip', 'pegawai', array('idspg_pegawai' => $row->id_pegawai));
            $arr['id_jenis_diklat']             = $row->id_jenis_diklat;
            $arr['nama']                         = $row->nama;
            $arr['tempat']                         = $row->tempat;
            $arr['angkatan']                       = $row->angkatan;
            $arr['tahun']                       = $row->tahun;
            $arr['lama_pendidikan']              = $row->lama_pendidikan;
            $arr['no_sttp']                     = $row->no_sttp;
            $arr['tgl_sttp']                     = $row->tgl_sttp;
            
            $form_action = base_url().'index.php/diklat/simpan_fungsional/true/'.$id;
            $form_id = 'form_diklat';
            
            $data['judul'] = 'UBAH DATA DIKLAT FUNGSIONAL';
            $data['list_data'] = $this->p->entry_diklat_fungsional($form_id,$form_action,$arr);
            $this->load->view('view_diklat', $data);
        } else {
            $data['judul'] = 'ERROR';
            $data['isi']   = 'Internal ID error.';
            $data['link_kembali'] = base_url().'index.php/diklat/fungsional';
            $this->load->view('view_blank', $data);
        }
    }
    
    function form_edit_teknis($id) {
		if (!$this->session->userdata('username')) {
			$data['isLogin'] = FALSE;
        	redirect("/login", "location");
		} else {
			$data['isLogin'] = TRUE;
			$data['username'] = $this->session->userdata('username');
			$data['role'] = $this->session->userdata('role');
		}
		
    	$form_action = base_url().'index.php/diklat/simpan_teknis/true/'.$id;
        $form_id = 'form_diklat';
    	$list_nip = $this->_getNIP();
    	if ($list_nip<>'') {
    		$auto_nip = '$("#nip").autocompleteArray(['.$list_nip.'], {delay:10,minChars:1,matchSubset:1,autoFill:true,maxItemsToShow:10});'; 
    	} else {
    		$auto_nip = ''; 
    	}
        $data['additional_js'] = $this->_setJsFormTeknis($auto_nip);

        $this->load->model('Datum_model', 'd');
        $this->db->where(array('idspg_diklat' => $id));
        $q = $this->db->get('diklat');
        if ($q->num_rows() > 0) {
            $row = $q->row();
            $nip2 = $this->d->getData('nip_baru', 'pegawai', array('idspg_pegawai' => $row->id_pegawai));
            $arr['nip']          				= $nip2!=''?$nip2:$this->d->getData('nip', 'pegawai', array('idspg_pegawai' => $row->id_pegawai));
            $arr['id_jenis_diklat']             = $row->id_jenis_diklat;
            $arr['nama']         			    = $row->nama;
            $arr['tempat']         				= $row->tempat;
            $arr['angkatan']           			= $row->angkatan;
            $arr['tahun']           			= $row->tahun;
            $arr['lama_pendidikan']          	= $row->lama_pendidikan;
            $arr['no_sttp']         			= $row->no_sttp;
            $arr['tgl_sttp']         			= $row->tgl_sttp;
            
            $form_action = base_url().'index.php/diklat/simpan_teknis/true/'.$id;
            $form_id = 'form_diklat';
            
            $data['judul'] = 'UBAH DATA DIKLAT TEKNIS';
            $data['list_data'] = $this->p->entry_diklat_teknis($form_id,$form_action,$arr);
            $this->load->view('view_diklat', $data);
        } else {
        	$data['judul'] = 'ERROR';
        	$data['isi']   = 'Internal ID error.';
        	$data['link_kembali'] = base_url().'index.php/diklat/teknis';
        	$this->load->view('view_blank', $data);
        }
    }

    function hapus($id,$jenis) {
        $this->db->where('idspg_diklat', $id);
        $this->db->delete('diklat');
        //redirect('diklat/'.$jenis, 'refresh');
    }
    
    
    function diklat_bisa_dihapus($id) {
    	echo 'bisa';
    }
    
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */